import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:lishopflu/base/base_import.dart';
import 'package:lishopflu/base/base_list_page.dart';
import 'package:lishopflu/base/view_import.dart';
import 'package:lishopflu/view/customer/appbar_search.dart';

import 'home_search_ctl.dart';
class HomeSearchPage extends BaseListPage<HomeSearchCtl>{

  @override
  void onCreate(BuildContext mContext) {

  }


  @override
  Widget pageBody(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 10, left: 10, right: 10),
      color: bgColor,
      child: Obx(() => listBody(
        context,
        StaggeredGridView.countBuilder(
          itemBuilder: (BuildContext context, int index){
            return itemBuilder(context, index);
          },
          crossAxisCount: 2,
          mainAxisSpacing: 5.0,
          crossAxisSpacing: 5.0,
          staggeredTileBuilder: (int index) => StaggeredTile.fit(1),/*new StaggeredTile.count(2, index.isEven ? 2 : 1)*/
          itemCount: controller.mList.length,
        ),
      ),
      ),
    );
  }

  @override
  Widget appbar() {
    return AppBarSearch(
      leading: CommonWidget.leading(() {
        finish();
      }),
      hintText: '请输入关键字',
      actions: [
        IconButton(icon:Icon(Icons.refresh), color: Colors.white,onPressed: ((){controller.refreshController.callRefresh();}),)
      ],
    );
  }

  /// 列表的item
  Widget itemBuilder(BuildContext context, int index){
    String item = controller.mList[index];
    return GestureDetector(
      onTap: ((){
        controller.toProductDetail({RouterKey.PRODUCT_ID: item, RouterKey.PRODUCT_NAME:'详情：'+index.toString()});
      }),
      child: Container(
        padding: EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Column(
          children: [
            Image.asset('images/about_github.png', width: 20,height: 20,),
            Text('￥：'+item, style: TextStyle(color: Colors.red, fontSize: 18, /*fontStyle: FontStyle.italic,*/ fontWeight: FontWeight.bold),),
            Text('描述：'+item),
            index.isEven?Text('购买人数：'+item):Padding(padding: EdgeInsets.zero),
          ],
        ),
      ),
    );
  }
}